/*
 *	ApOS (Another Project software for s3c2410)
 *	
 *	This program is free software; you can redistribute it and/or modify
 *	it under the terms of the GNU General Public License version 2 as
 *	published by the Free Software Foundation.
 *			
 *
 */
#include <stdarg.h>

#include "../include/s3c2410/serial.h"
#include "../include/s3c2410/lcd.h"
#include "../include/s3c2410/s3c2410.h"
#include "../include/s3c2410/cpu.h"
#include "../include/kernel/task.h"

extern delayLoopCount;

char buf[1024];

extern struct task_struct* p_current_task;


void uart_printf(char *fmt,...)
{

	va_list args;
	va_start(args,fmt);
	vsprintf(buf,fmt,args);
	va_end(args);
	uart0_send_string(buf);
}



char* sprintk(char *str,char *fmt,...)
{
	va_list args;
	va_start(args,fmt);
	vsprintf(str,fmt,args);
	va_end(args);
	return str;
}

void delay(int time)
{
	int i;
	for(;time>0;time--)
		for(i=0;i<delayLoopCount;i++);
}

void dump_cpu()
{
	unsigned int cpsr,spsr;
	unsigned int r0,r1,r2,r3,r4,r5,r6,r7,r8,r9,r10,r11,r12,r13,r14,r15;
	asm volatile(
		"str r0,%0 \n\t"
		"str r1,%1 \n\t"
		"str r2,%2 \n\t"
		"str r3,%3 \n\t"
		"str r4,%4 \n\t"
		"str r5,%5 \n\t"
		"str r6,%6 \n\t"
		"str r7,%7 \n\t"
		"str r8,%8 \n\t"
		"str r9,%9 \n\t"
		"str r10,%10 \n\t"
		"str r11,%11 \n\t"
		"str r12,%12 \n\t"
		"str r13,%13 \n\t"
		"str r14,%14 \n\t"
		"str r15,%15 \n\t"
		"mrs r0,cpsr \n\t"
		"str r0,%16 \n\t"
		"mrs r0,spsr \n\t"
		"str r0,%17 \n\t"		
		::"m"(r0),"m"(r1),"m"(r2),"m"(r3),"m"(r4),"m"(r5),"m"(r6),"m"(r7),
		"m"(r8),"m"(r9),"m"(r10),"m"(r11),"m"(r12),"m"(r13),"m"(r14),"m"(r15),"m"(cpsr),"m"(spsr)
	);
	printk("r0: %0x\nr1: %0x\nr2: %0x\nr3: %0x\nr4: %0x\nr5: %0x\nr6: %0x\nr7: %0x\nr8: %0x\nr9: %0x\nr10: %0x\nr11: %0x\nr12: %0x\nr13: %0x\nr14: %0x\nr15: %0x\ncpsr: %0x\nspsr: %0x\n",
	r0,r1,r2,r3,r4,r5,r6,r7,r8,r9,r10,r11,r12,r13,r14,r15,cpsr,spsr);
}
